package com.zhangkunhao.notes.view;

import com.zhangkunhao.notes.controller.CancelListener;
import com.zhangkunhao.notes.controller.UserMenuListener;
import com.zhangkunhao.notes.entity.DO.User;

import java.awt.*;
import javax.swing.*;

/**
 * 用户菜单界面
 *
 * @author 张坤浩
 */
public class UserMenuView extends JFrame {
    private JFrame frame;
    private User user;

    public UserMenuView(JFrame frame, User user) {
        this.frame = frame;
        this.user = user;
    }

    public UserMenuView() {
    }

    public void initComponents() {
        setFont(new Font(Font.DIALOG, Font.PLAIN, 18));
        //分享⾃⼰的地狱笑话
        JButton button1 = new JButton();
        //消耗功德查看别人的笑话
        JButton button2 = new JButton();
        //参加各种积攒功德的活动
        JButton button3 = new JButton();
        //编辑个⼈信息
        JButton button4 = new JButton();
        //消耗功德数量前⼗排⾏榜
        JButton button5 = new JButton();
        //现有功德数量前⼗排⾏榜
        JButton button6 = new JButton();
        //查看其他用户信息
        JButton button7 = new JButton();
        //退出
        JButton button8 = new JButton();

        JLabel label1 = new JLabel();

        //======== this ========
        setTitle("用户菜单");
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- button1 ----
        button1.setText("分享⾃⼰的地狱笑话");
        contentPane.add(button1);
        button1.setBounds(new Rectangle(new Point(135, 35), button1.getPreferredSize()));

        //---- button2 ----
        button2.setText("消耗功德查看别人的笑话");
        contentPane.add(button2);
        button2.setBounds(135, 85, 142, 30);

        //---- button3 ----
        button3.setText("参加各种积攒功德的活动");
        contentPane.add(button3);
        button3.setBounds(new Rectangle(new Point(135, 140), button3.getPreferredSize()));

        //---- button4 ----
        button4.setText("编辑个⼈信息");
        contentPane.add(button4);
        button4.setBounds(135, 195, 142, 30);

        //---- button5 ----
        button5.setText("消耗功德数量前⼗排⾏榜");
        contentPane.add(button5);
        button5.setBounds(135, 255, 300, 35);

        //---- button6 ----
        button6.setText("现有功德数量前⼗排⾏榜");
        contentPane.add(button6);
        button6.setBounds(140, 365, 165, 35);

        //---- button7 ----
        button7.setText("查看其他用户信息");
        contentPane.add(button7);
        button7.setBounds(140, 420, 165, 35);

        //---- button8 ----
        button8.setText("退出");
        contentPane.add(button8);
        button8.setBounds(140, 515, 100, 35);

        contentPane.add(label1);
        label1.setBounds(55, 15, 740, 500);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for (int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        this.setVisible(true);
        //绑定监听事件
        UserMenuListener userMenuListener = new UserMenuListener(user);
        button1.addActionListener(userMenuListener);
        button2.addActionListener(userMenuListener);
        button3.addActionListener(userMenuListener);
        button4.addActionListener(userMenuListener);
        button5.addActionListener(userMenuListener);
        button6.addActionListener(userMenuListener);
        button7.addActionListener(userMenuListener);
        button8.addActionListener(new CancelListener(frame, this));
    }
}
